﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic.Security;

namespace Otgruzka
{
    public partial class TopMenu : System.Web.UI.UserControl
    {
        protected override void OnInit(EventArgs e)
        {
            LoginStatus1.LoggedOut += new EventHandler(LoginStatus1_LoggedOut);

            if (UserPrincipal.Current == null)
            {
                LoginStatus1.Visible = false;
            }
        }

        void LoginStatus1_LoggedOut(object sender, EventArgs e)
        {
            AuthenticationService.SingOut();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            UserLogin.Visible = false;
            UserName.Visible = false;

            if (UserPrincipal.Current != null)
            {
                if (UserPrincipal.Current.UserId > 0)
                {
                    if (UserPrincipal.Current.Identity.IsAuthenticated)
                    {
                        if (!string.IsNullOrEmpty(UserPrincipal.Current.UserFullName))
                        {
                            UserName.InnerText = string.Format("{0}  |  {1}  |  {2}", UserPrincipal.Current.JuridicalPersonName, UserPrincipal.Current.DepartmentName, UserPrincipal.Current.UserFullName);
                            UserName.Visible = true;
                            UserName.Attributes["title"] = string.Format("{0}  |  {1}  |  {2}", UserPrincipal.Current.JuridicalPersonName, UserPrincipal.Current.DepartmentName, UserPrincipal.Current.UserFullName);
                        }
                        if (UserPrincipal.Current.LoginName != "")
                        {
                            UserLogin.InnerText = " [ " + UserPrincipal.Current.LoginName + " ] ";
                            UserLogin.Visible = true;//(
                        }
                    }
                }
            }
        }


    }
}